<!--
  * 计算公式下拉选择框
  *
  * @Author:    zzx
  * @Date:      2025-08-05 10:54:11
  * @Copyright  zzx
-->
<template>
  <a-select
      v-model:value="selectValue"
      :style="`width: ${width}`"
      :placeholder="props.placeholder"
      :showSearch="true"
      :allowClear="true"
      :size="size"
      @change="onChange"
  >
    <a-select-option v-for="item in employeeList" :key="item.funcId" :value="item.funcId">
      {{ item.funcName }}
    </a-select-option>
  </a-select>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue';
import { funcExpressionApi } from '/@/api/business/expression/func-expression-api';
import { smartSentry } from '/@/lib/smart-sentry';

// =========== 属性定义 和 事件方法暴露 =============

const props = defineProps({
  value: [Number, Array],
  placeholder: {
    type: String,
    default: '请选择',
  },
  width: {
    type: String,
    default: '100%',
  },
  size: {
    type: String,
    default: 'default',
  },
  // 角色ID，可为空
  funcName: {
    type: String,
    default: null,
  },
  // 禁用标识
  disabledFlag: {
    type: Number,
    default: 0,
  },
});

const emit = defineEmits(['update:value', 'change']);

// =========== 查询数据 =============

//员工列表数据
const employeeList = ref([]);
async function query() {
  try {
    let params = {
      pageNum: 1,
      pageSize: 1,
    };
    if (null != props.disabledFlag) {
      params.disabledFlag = props.disabledFlag;
    }
    if (null != props.funcName) {
      params.funcName = props.funcName;
    }
    let resp = await funcExpressionApi.queryAll(params);
    employeeList.value = resp.data;
  } catch (e) {
    smartSentry.captureError(e);
  }
}
onMounted(query);

// =========== 选择 监听、事件 =============

const selectValue = ref(props.value);
watch(
    () => props.value,
    (newValue) => {
      selectValue.value = newValue;
    }
);

function onChange(value) {
  emit('update:value', value);
  emit('change', value);
  console.log("=========   onChange  " + value)
}
</script>
